<template>
    <div>
 <h1>修改用药页面</h1>
    </div>
     <table class="table">    
          <tbody>
              <tr>  
                 <td>药品名称</td>
                 <td>
                    <input type="text"  v-model="data.medicationName">
                 </td>
              </tr>

              <tr>  
                 <td>科室类型</td>
                 <td>
                    <select v-model="data.departmentId">
                        <option value="0">==请选择科室类型==</option>
                        <option v-for="a in obj" :value="a.departmentId">{{a.departmentNmae}}</option>
                    </select>
                 </td>
              </tr>

              <tr>  
                 <td>用药日期</td>
                 <td>
                    <input type="date" v-model="data.medicationDate">
                 </td>
              </tr>

              <tr>  
                 <td>病人名称</td>
                 <td>
                         <input type="text"  v-model="data.name">
                 </td>
              </tr>

              <tr>  
                 <td>病房号码</td>
                 <td>
                     <input type="text"  v-model="data.medicationPhone">
                 </td>
              </tr>

              <tr>  
                 <td>配药医生</td>
                 <td>
                     <input type="text"  v-model="data.doctor">
                 </td>
              </tr>

                <tr>  
                 <td></td>
                 <td>
                    <input type="button" value="新增" @click="as">
                 </td>
              </tr>
          </tbody>
     </table>
</template>

<script setup lang="ts">
 import axios from 'axios';
  import {ref,onMounted} from 'vue';
  import moment from 'moment';

  import {useRouter,useRoute} from 'vue-router';

   const route=useRoute();
 const router=useRouter();
 onMounted(()=>{
    departments();
    Finds();

    
 })

 const obj=ref({
    "departmentId": 0,
    "departmentNmae": "",
    "departmentImg": "",
    "departmentDate": ""
 })
 const departments=()=>{
     axios.get("https://localhost:7170/api/Department/departments").then(res=>{
          obj.value=res.data;

     })
 }

  const Finds=()=>{
 let id=route.query.medicationId;
  axios.get("https://localhost:7170/api/Medication/FindMedication?id="+id).then(res=>{
      data.value=res.data;
       data.value.medicationDate=moment(data.value.medicationDate).format("yyyy-MM-DD");

    
  })

  }

 const data=ref({
    "medicationId": 0,
  "medicationName": "",
  "departmentId": 0,
  "medicationDate": "2025-07-09T13:25:57.959Z",
  "name": "",
  "medicationPhone": "",
  "doctor": "",
  "state": true,
  "isDelete": true
 })
  
    const as=()=>{

            if(data.value.medicationName==""){
          alert("药品名称不能为空");
           return;
       }

        if(data.value.departmentId==0){
          alert("科室类型不能为空");
           return;
       }


        if(data.value.name==""){
          alert("病人名称不能为空");
           return;
       }

       if(data.value.medicationPhone==""){
          alert("病房号码不能为空");
           return;
       }    

         if(data.value.doctor==""){
          alert("配药医生不能为空");
           return;
       }

      axios.post("https://localhost:7170/api/Medication/UpadateAnync",data.value).then(res=>{
           if(res.data>0){
               alert("修改成功");
               return;
          }else{
               alert("修改失败");     
                   }
     })
    }
   
</script>

<style scoped>

</style>
